import cv2
import numpy as np

# capture=cv2.VideoCapture(r'C:\Users\Lenovo\Desktop\OpenCV上课需用到的视频.avi')
capture=cv2.VideoCapture(1)
four_cc=cv2.VideoWriter_fourcc('X','V','I','D')
out=cv2.VideoWriter(r'C:\Users\Lenovo\Desktop\output.avi',four_cc,20,(640,480))
while(capture.isOpened()):
    ret,frame=capture.read()
    if ret==True:
        out.write(frame)
        print(ret)
        cv2.imshow('img',frame)
        if cv2.waitKey(1)==32:
            break
cv2.destroyAllWindows()
capture.release()
out.release()